datablock AudioProfile(DestroyableObjectExplosionSound)
{
	filename = "~/data/sound/Crossbow_explosion.ogg";
	description = AudioDefault3d;
	preload = true;
};

datablock ParticleData(DestroyableObjectExplosionFire)
{
   textureName          = "~/data/shapes/particles/fire";
   dragCoeffiecient     = 100.0;
   gravityCoefficient   = 0;
   inheritedVelFactor   = 0.25;
   constantAcceleration = 0.1;
   lifetimeMS           = 500;
   lifetimeVarianceMS   = 400;
   useInvAlpha =  false;
   spinRandomMin = -80.0;
   spinRandomMax =  80.0;

   colors[0]     = "0.8 0.4 0 0.8";
   colors[1]     = "0.2 0.0 0 0.8";
   colors[2]     = "0.0 0.0 0.0 0.0";

   sizes[0]      = 0.5;
   sizes[1]      = 1.5;
   sizes[2]      = 3;

   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(DestroyableObjectExplosionFireEmitter)
{
   ejectionPeriodMS = 150;
   periodVarianceMS = 100;
   ejectionVelocity = 0.8;
   velocityVariance = 0.5;
   thetaMin         = 0.0;
   thetaMax         = 180.0;
   lifetimeMS       = 180;
   particles		= "DestroyableObjectExplosionFire";
};

datablock ParticleData(DestroyableObjectExplosionSmoke)
{
   textureName          = "~/data/shapes/particles/smoke";
   dragCoeffiecient     = 100.0;
   gravityCoefficient   = 0;
   inheritedVelFactor   = 0.25;
   constantAcceleration = -0.30;
   lifetimeMS           = 610;
   lifetimeVarianceMS   = 200;
   useInvAlpha =  true;
   spinRandomMin = -80.0;
   spinRandomMax =  80.0;

   colors[0]     = "0.56 0.36 0.26 1.0";
   colors[1]     = "0.2 0.2 0.2 1.0";
   colors[2]     = "0.0 0.0 0.0 0.0";

   sizes[0]      = 2.0;
   sizes[1]      = 3.0;
   sizes[2]      = 4.0;

   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(DestroyableObjectExplosionSmokeEmitter)
{
   ejectionPeriodMS = 300;
   periodVarianceMS = 0;
   ejectionVelocity = 4;
   velocityVariance = 2;
   thetaMin         = 0.0;
   thetaMax         = 180.0;
   lifetimeMS       = 50;
   particles		= "DestroyableObjectExplosionSmoke";
};

datablock ParticleData(DestroyableObjectExplosionSparks)
{
   textureName          = "~/data/shapes/particles/spark";
   dragCoefficient      = 1;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 500;
   lifetimeVarianceMS   = 350;

   colors[0]     = "0.60 0.40 0.30 1.0";
   colors[1]     = "0.60 0.40 0.30 1.0";
   colors[2]     = "1.0 0.40 0.30 0.0";

   sizes[0]      = 0.25;
   sizes[1]      = 0.15;
   sizes[2]      = 0.15;

   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(DestroyableObjectExplosionSparkEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 1;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   orientParticles  = true;
   lifetimeMS       = 100;
   particles		= "DestroyableObjectExplosionSparks";
};

datablock ParticleData(DestroyableObjectDebrisTrail)
{
   textureName          = "~/data/shapes/particles/fire";
   dragCoefficient      = 1;
   gravityCoefficient   = 0;
   inheritedVelFactor   = 0;
   windCoefficient      = 0;
   constantAcceleration = 0;
   lifetimeMS           = 800;
   lifetimeVarianceMS   = 100;
   spinSpeed     = 0;
   spinRandomMin = -90.0;
   spinRandomMax =  90.0;
   useInvAlpha   = true;

   colors[0]     = "0.8 0.3 0.0 1.0";
   colors[1]     = "0.1 0.1 0.1 0.7";
   colors[2]     = "0.1 0.1 0.1 0.0";

   sizes[0]      = 0.2;
   sizes[1]      = 0.3;
   sizes[2]      = 0.4;

   times[0]      = 0.1;
   times[1]      = 0.2;
   times[2]      = 1.0;
};


datablock ParticleEmitterData(DestroyableObjectDebrisTrailEmitter)
{
   ejectionPeriodMS = 30;
   periodVarianceMS = 0;
   ejectionVelocity = 0.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 170;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   lifetimeMS       = 5000;
   particles = "DestroyableObjectDebrisTrail";
};

datablock ParticleData(DestroyableObjectDebrisSpark)
{
   textureName          = "~/data/shapes/particles/fire";
   dragCoefficient      = 0;
   gravityCoefficient   = 0.0;
   windCoefficient      = 0;
   inheritedVelFactor   = 0.5;
   constantAcceleration = 0.0;
   lifetimeMS           = 500;
   lifetimeVarianceMS   = 50;
   spinRandomMin = -90.0;
   spinRandomMax =  90.0;
   useInvAlpha   = false;

   colors[0]     = "0.8 0.2 0 1.0";
   colors[1]     = "0.8 0.2 0 1.0";
   colors[2]     = "0 0 0 0.0";

   sizes[0]      = 0.2;
   sizes[1]      = 0.3;
   sizes[2]      = 0.1;

   times[0]      = 0.0;
   times[1]      = 0.5;
   times[2]      = 1.0;
};

datablock ParticleEmitterData(DestroyableObjectDebrisSparkEmitter)
{
   ejectionPeriodMS = 20;
   periodVarianceMS = 0;
   ejectionVelocity = 0.5;
   velocityVariance = 0.25;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvances = false;
   orientParticles  = false;
   lifetimeMS       = 300;
   particles = "DestroyableObjectDebrisSpark";
};

datablock ExplosionData(DestroyableObjectDebrisExplosion)
{
   emitter[0] = DestroyableObjectDebrisSparkEmitter;

   shakeCamera = false;
   impulseRadius = 0;
   lightStartRadius = 0;
   lightEndRadius = 0;
};

datablock DebrisData(DestroyableObjectExplosionDebris)
{
   shapeFile = "~/data/shapes/crossbow/debris.dts";
   emitters = "DestroyableObjectDebrisTrailEmitter";
   explosion = DestroyableObjectDebrisExplosion;
   
   elasticity = 0.6;
   friction = 0.5;
   numBounces = 1;
   bounceVariance = 1;
   explodeOnMaxBounce = true;
   staticOnMaxBounce = false;
   snapOnMaxBounce = false;
   minSpinSpeed = 0;
   maxSpinSpeed = 700;
   render2D = false;
   lifetime = 2;
   lifetimeVariance = 0.4;
   velocity = 5;
   velocityVariance = 0.5;
   fade = false;
   useRadiusMass = true;
   baseRadius = 0.3;
   gravModifier = 0.5;
   terminalVelocity = 6;
   ignoreWater = true;
};

datablock ExplosionData(DestroyableObjectSubExplosion1)
{
   offset = 0;
   emitter[0] = DestroyableObjectExplosionSmokeEmitter;
   emitter[1] = DestroyableObjectExplosionSparkEmitter;
};

datablock ExplosionData(DestroyableObjectSubExplosion2)
{
   offset = 1.0;
   emitter[0] = DestroyableObjectExplosionSmokeEmitter;
   emitter[1] = DestroyableObjectExplosionSparkEmitter;
};


datablock ExplosionData(DestroyableObjectExplosion)
{
   soundProfile = DestroyableObjectExplosionSound;
   lifeTimeMS = 500;

   // Volume particles
   particleEmitter = DestroyableObjectExplosionFireEmitter;
   particleDensity = 25;
   particleRadius = 2;

   // Point emission
   emitter[0] = DestroyableObjectExplosionSmokeEmitter;
   emitter[1] = DestroyableObjectExplosionSparkEmitter;
   
   // Sub explosion objects
   subExplosion[0] = DestroyableObjectSubExplosion1;
   subExplosion[1] = DestroyableObjectSubExplosion2;
   
   // Camera Shaking
   shakeCamera = true;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Exploding debris
   debris = DestroyableObjectExplosionDebris;
   debrisThetaMin = 0;
   debrisThetaMax = 60;
   debrisPhiMin = 0;
   debrisPhiMax = 360;
   debrisNum = 4;
   debrisNumVariance = 3;
   debrisVelocity = 0.8;
   debrisVelocityVariance = 0.5;
   
   // Impulse
   impulseRadius = 5;
   impulseForce = 25;

   // Dynamic light
   lightStartRadius = 6;
   lightEndRadius = 3;
   lightStartColor = "0.5 0.5 0";
   lightEndColor = "0 0 0";
};














datablock StaticShapeData(Crate)
{
	category            = "DestroyableCrates";
	shapeFile           = "~/data/shapes/crates&barrels/crate.dts";
	directDamage        = 5;
	radiusDamage        = 10;
	damageRadius        = 10;
	areaImpulse         = 20;
	
	maxDamage			= 10;
	//damageType			= "PowerCrystalDebris";
};

function Crate::OnAdd(%this, %obj)
{
}

function Crate::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	%obj.applyDamage(%damage);
	if (%obj.getDamageLevel() >= %this.maxDamage)
		%this.Explode(%obj, %pos);
}

function Crate::Explode(%this, %obj, %pos)
{
	if (%obj.exploded)
		return;
	
	%obj.exploded = true;
	%boom = new Explosion()
	{
		datablock		= DestroyableObjectExplosion;
		position		= %pos;
		sourceObject	= %obj.sourceObject;
		sourceSlot		= %obj.sourceSlot;
		client			= %obj.client;
	};
	MissionCleanup.add(%boom);
	%obj.setHidden(true);
}




datablock StaticShapeData(BatteredCrate : Crate)
{
	category            = "DestroyableCrates";
	shapeFile           = "~/data/shapes/crates&barrels/crate.dts";
};

function BatteredCrate::OnAdd(%this, %obj)
{
	%obj.setSkinName("battered");
}

function BatteredCrate::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function BatteredCrate::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(StainedCrate : Crate)
{
	category            = "DestroyableCrates";
	shapeFile           = "~/data/shapes/crates&barrels/crate.dts";
};

function StainedCrate::OnAdd(%this, %obj)
{
	%obj.setSkinName("stained");
}

function StainedCrate::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function StainedCrate::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(YellowCrate : Crate)
{
	category            = "DestroyableCrates";
	shapeFile           = "~/data/shapes/crates&barrels/crate_a.dts";
};

function YellowCrate::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function YellowCrate::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(DangerCrate : Crate)
{
	category            = "DestroyableCrates";
	shapeFile           = "~/data/shapes/crates&barrels/crate_b.dts";
};

function DangerCrate::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function DangerCrate::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(Barrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel.dts";
};

function Barrel::OnAdd(%this, %obj)
{
}

function Barrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function Barrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(StainedBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel.dts";
};

function StainedBarrel::OnAdd(%this, %obj)
{
	%obj.setSkinName("stained");
}

function StainedBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function StainedBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}



datablock StaticShapeData(CorrodedBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel.dts";
};

function CorrodedBarrel::OnAdd(%this, %obj)
{
	%obj.setSkinName("corroded");
}

function CorrodedBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function CorrodedBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(BatteredBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel.dts";
};

function BatteredBarrel::OnAdd(%this, %obj)
{
	%obj.setSkinName("battered");
}

function BatteredBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function BatteredBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(RustedBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel.dts";
};

function RustedBarrel::OnAdd(%this, %obj)
{
	%obj.setSkinName("rusted");
}

function RustedBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function RustedBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(FuelBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel.dts";
};

function FuelBarrel::OnAdd(%this, %obj)
{
	%obj.setSkinName("fuel");
}

function FuelBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function FuelBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(ToxicBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel.dts";
};

function ToxicBarrel::OnAdd(%this, %obj)
{
	%obj.setSkinName("toxic");
}

function ToxicBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function ToxicBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(GreenBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel_a.dts";
};

function GreenBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function GreenBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(GreenStripedBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel_b.dts";
};

function GreenStripedBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function GreenStripedBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(RibbedBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel_c.dts";
};

function RibbedBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function RibbedBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}




datablock StaticShapeData(RibbedDangerBarrel : Crate)
{
	category            = "DestroyableBarrel";
	shapeFile           = "~/data/shapes/crates&barrels/barrel_d.dts";
};

function RibbedDangerBarrel::Damage(%this, %obj, %sourceObject, %pos, %damage, %damageType)
{
	Crate.Damage(%obj, %sourceObject, %pos, %damage, %damageType);
}

function RibbedDangerBarrel::Explode(%this, %obj, %pos)
{
	Crate.Explode(%obj, %pos);
}